# Maintainer (MSYS2): Ray Donnelly <mingw.android@gmail.com>
# Contributor: Zach Bacon <zachbacon@vba-m.com>

_variant=-${KF5_VARIANT:-shared}
source "$(dirname ${BASH_SOURCE[0]})"/../mingw-w64-PKGBUILD-common/kde-frameworks5
_kde_f5_init_package "${_variant}" "kimageformats"
pkgver=5.116.0
pkgrel=2
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
msys2_references=(
  'archlinux: kimageformats5'
  "cpe: cpe:/a:kde:kimageformats"
)
pkgdesc="Plugins to allow QImage to support extra file formats (mingw-w64)"
license=('LGPL')
makedepends=("${MINGW_PACKAGE_PREFIX}-extra-cmake-modules>=${pkgver}"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-libavif"
             "${MINGW_PACKAGE_PREFIX}-libheif"
             "${MINGW_PACKAGE_PREFIX}-libraw"
             "${MINGW_PACKAGE_PREFIX}-libjxl"
             "${MINGW_PACKAGE_PREFIX}-openexr"
             "${MINGW_PACKAGE_PREFIX}-karchive-qt5${_namesuff}>=${pkgver}")
optdepends=("${MINGW_PACKAGE_PREFIX}-libavif: AVIF format support"
            "${MINGW_PACKAGE_PREFIX}-libheif: HEIF format support"
            "${MINGW_PACKAGE_PREFIX}-libraw: RAW format support"
            "${MINGW_PACKAGE_PREFIX}-libjxl: JPEG XL format support"
            "${MINGW_PACKAGE_PREFIX}-openexr: EXR format support"
            "${MINGW_PACKAGE_PREFIX}-karchive-qt5${_namesuff}>=${pkgver}: plugin for Krita and OpenRaster images")
depends=()
if [ "${_variant}" = "-static" ]; then
  _kde_f5_add_depends "${_variant}" "${MINGW_PACKAGE_PREFIX}-qt5${_namesuff}"
else
  depends+=("${MINGW_PACKAGE_PREFIX}-qt5-base")
fi
groups=("${MINGW_PACKAGE_PREFIX}-kf5")
source=("https://download.kde.org/stable/frameworks/${pkgver%.*}/${_basename}-${pkgver}.tar.xz"{,.sig})
sha256sums=('7c119bcd5ef7963aac00b7d2736bfe87393f6e5d67d201c5fe399e3ab4188f9c'
            'SKIP')
validpgpkeys=('53E6B47B45CEA3E0D5B7457758D0EE648A48B3BB') # David Faure <faure@kde.org>

prepare() {
  cd "${srcdir}"/${_basename}-${pkgver}

  mkdir -p "${srcdir}"/build-${MSYSTEM}${_variant}
}

build() {
  local -a extra_config
  cd build-${MSYSTEM}${_variant}
  if [ "${_variant}" = "-static" ]; then
    extra_config+=( -DBUILD_SHARED_LIBS=NO )
  fi

  _kde_f5_build_env
  ${MINGW_PREFIX}/bin/cmake.exe ../${_basename}-${pkgver} \
    -DCMAKE_BUILD_TYPE=$(_kde_f5_CMAKE_BUILD_TYPE) \
    "${_kde_f5_KDE_INSTALL_DIRS[@]}" \
    -DBUILD_QCH=OFF \
    -DBUILD_TESTING=OFF \
    -DKIMAGEFORMATS_HEIF=ON \
    -DECM_DIR=${MINGW_PREFIX}/share/ECM \
    "${extra_config[@]}" \
    -G'Ninja'
  ${MINGW_PREFIX}/bin/cmake.exe --build ./
}

package() {
  cd build-${MSYSTEM}${_variant}
  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/cmake.exe --install ./
}
